import json

from django.http import HttpResponse
from django.views import View


class Deal(View):
    def post(self, request):
        dict = json.loads(request.body.decode())
        key = dict['key']
        value = dict['value']
        response = HttpResponse()
        response.set_cookie(key, value, max_age=3600)
        return HttpResponse('key:value添加成功')

    def get(self, request):
        key = request.GET.get('key')
        value = request.COOKIES.get(key)
        return HttpResponse(f'{key}:{value}')
